﻿@model thailandProject.Models.ClientReservation

@{
    ViewBag.Title = "View Client";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->
    <div class="clientgeninfo">
        <div id="viewclientname">
            <div style="margin-right:6px; float:left;">
                @Html.DisplayFor(model => model.client.clientFirstName)
            </div>
            <div style="margin-right:6px; float:left;">
                @Html.DisplayFor(model => model.client.clientLastName)
            </div>
        </div>
        <div id="viewclientemail">
            <div style="margin-right:3px; float:left;">
                @Html.DisplayFor(model => model.client.clientEmail)
            </div>
        </div>
        <div class="viewclientrow" style="color:#333333;">
            <div style="width:100%; float:left;">
                @Html.DisplayFor(model => model.client.clientAddress)
            </div>
            <div style="margin-right:3px; float:left;">
                @Html.DisplayFor(model => model.client.clientCity)
            </div>
            <div style="margin-right:3px; float:left;">
                @Html.DisplayFor(model => model.client.clientStateProvidence)
            </div>
        </div>
        <div class="viewclientrow" style="color:#333333;">
            <p>
                @{
                    int up = (int)Session["userPerm"];

                    if (up <= 2)
                    {
                        @Html.ActionLink("Edit", "EditClient", new { clientId = Model.client.clientID }) @:|
                    }
                    //Delete option:
                    if (up <= 2)
                    {
                        @Html.ActionLink("Delete", "DeleteClient", new { clientId = Model.client.clientID }, new { onclick = "return warning()" })
                        <script>
                            function warning() {
                                return confirm('Are you sure?\n\nThis will delete the client, but will keep any payments, tasks, and reservations for historical purposes.');
                            }
                        </script>
                    } @:|
                    
                    @Html.ActionLink("View Emails", "ViewEmails", new { clientId = Model.client.clientID })
                    
                }
            </p>
        </div>
    </div>
    <div class="clientotherinfo">
        <div class="viewclientrow" style="color:#777777; font-weight:bold;">
            FINANCIAL INFO
        </div>
        <div class="viewclientrow">
            <div style="margin-right:3px; float:left;">
                Amount Owed:
            </div>
            <div style="margin-right:3px; float:left; color:#333333;">
                @if (Model.reservations.Count > 0)
                {
                    //Only display the amount owed if a recent reservation exists
                    @:&#3647; 
                    @Html.DisplayFor(model => model.quotedPrice)
                }
                else
                {
                    @:None
                }
            </div><br />

            <div style="margin-right:3px; float:left;">
                Amount Paid:
            </div>
            <div style="margin-right:3px; float:left; color:#333333;">
                @if (Model.reservations.Count > 0)
                {
                    //Only display the amount owed if a recent reservation exists
                    @:&#3647; 
                    @Html.DisplayFor(model => model.amountPaid)
                }
                else
                {
                    @:None
                }
            </div><br />
            
            <div style="margin-right:3px; float:left;">
                Balance Due:
            </div>
            <div style="margin-right:3px; float:left; color:#333333;">
                @if (Model.reservations.Count > 0)
                {
                    //Only display the amount owed if a recent reservation exists
                    @:&#3647; 
                    @Html.DisplayFor(model => model.balanceDue)
                }
                else
                {
                    @:None
                }
            </div><br />
            @Html.ActionLink("Payment History...", "ViewClientPayments", new { clientId = Model.client.clientID })
        </div>

        <div class="viewclientrow" style="color:#777777; font-weight:bold;">
            RESERVATION INFO
        </div>
        <div class="viewclientrow">
            @if (Model.reservations.Count > 0)
            {
                foreach (var r in Model.reservations)
                {
                    <div style="margin-right:3px; float:left;">
                    Property:
                    </div>
                    <div style="margin-right:3px; float:left; color:#333333;">
                    @r.property.propName
                    @if (r.reservation.resIsHeld)
                    {
                        <span style="color:black; font-size:smaller;"> (Unconfirmed)</span>
                    }
                    </div><br />
                    <div style="margin-right:3px; float:left;">
                        Start Date:
                    </div>
                    <div style="margin-right:3px; float:left; color:#333333;">
                    @r.reservation.resStartDate.ToShortDateString()
                    </div><br />
                    <div style="margin-right:3px; float:left;">
                        End Date:
                    </div>
                    <div style="margin-right:3px; float:left; color:#333333;">
                    @r.reservation.resEndDate.ToShortDateString()
                    </div><br />
                    <div style="margin-right:3px; float:left;">
                        Price:
                    </div>
                    <div style="margin-right:3px; float:left; color:#333333;">
                    @{
                    string price = @r.reservation.resQuotedPrice.ToString();
                    if (price.IndexOf('.') + 3 < price.Length - 1)
                    {
                        price = price.Substring(0, price.IndexOf('.') + 3);
                    }
                    }
                        &#3647; @price
                    </div><br />
                    if ((int)Session["userPerm"] <= 2)
                    {
                        string confirm_reservation_link = @"/Clients/ConfirmReservation?clientId=" + Model.client.clientID + @"&resID=" + r.reservation.resID;
                        string cancel_reservation_link = @"/Clients/DeleteReservation?resID=" + r.reservation.resID;
                        string edit_reservation_link = @"/Clients/EditClientReservation?resId=" + r.reservation.resID;

                        if (!r.reservation.resIsHeld)
                        {
                            <a href="@confirm_reservation_link"><img class="resConfirmButtons" src="../../images/addpayment_icon_small_long.png" alt="confirm" /></a>
                        }
                        else
                        {
                            <a href="@confirm_reservation_link"><img class="resConfirmButtons" src="../../images/confirm_button.png" alt="confirm" /></a>
                        }
                        <a href="@cancel_reservation_link" onclick="return confirm('Are you sure?')"><img class="resConfirmButtons" src="../../images/cancel_button.png" alt="cancel" /></a>
                        <a href="@edit_reservation_link"><img class="resConfirmButtons" src="../../images/edit_button_lowercase.png" alt="cedit" /></a>
                
                        if (!r.reservation.resIsHeld)
                        {
                            string add_task_link = @"/Clients/AddClientTask?clientId=" + Model.client.clientID + @"&resID=" + r.reservation.resID + @"&clientName=" + Model.client.clientFirstName + @"%20" + Model.client.clientLastName;
                            <a href="@add_task_link"><img class="resConfirmButtons" src="../../images/addtask_small_long.png" alt="edit" /></a>
                        }
                    }
                    <br /><br />
                }
            }
            else
            {
                <p>No upcoming reservations.</p>
            }
        </div>
        <div class="viewclientrow" style="color:#777777; font-weight:bold;">
            UPCOMING TASKS
        </div>
        <div class="viewclientrow">
            @if (Model.clientTasks.Count > 0)
            {
                foreach (var tc in Model.clientTasks)
                {
                    string completed = tc.taskComplete.ToString();
                    string date = tc.taskDueDate.Month + "/" + tc.taskDueDate.Day + "/" + tc.taskDueDate.Year + " ";
                    bool AM = true;
                    string clientName = tc.RESERVATION.CLIENT.clientFirstName + " " + (String.IsNullOrEmpty(tc.RESERVATION.CLIENT.clientLastName) ?
                        "" : tc.RESERVATION.CLIENT.clientLastName.Substring(0, 1) + ".");

                    if (tc.taskDueDate.Hour == 0)
                    {
                        date += "12";
                    }
                    else if (tc.taskDueDate.Hour < 12)
                    {
                        date += tc.taskDueDate.Hour;
                    }
                    else if (tc.taskDueDate.Hour == 12)
                    {
                        date += tc.taskDueDate.Hour;
                        AM = false;
                    }
                    else
                    { //It's 1 PM to 11 PM
                        date += tc.taskDueDate.Hour - 12;
                        AM = false;
                    }

                    date += ":";
                    if (tc.taskDueDate.Minute < 10)
                    {
                        date += "0" + tc.taskDueDate.Minute;
                    }
                    else
                    {
                        date += tc.taskDueDate.Minute;
                    }

                    if (AM)
                    {
                        date += " AM";
                    }
                    else
                    {
                        date += " PM";
                    }
                    <div class="pickups_header_half" onclick="$(this).next().slideToggle('fast');" @if (tc.taskTypeID == 0)
                                                                                                   {
                                                @:style="background: url('/images/menubar_gold.jpg') repeat-x scroll bottom left transparent;"
                                                }>
                        <div class="guestname_half">
                            @clientName
                        </div>
                        <div class="datetime_half">
                            @date
                        </div>
                        <div class="location_half">
                            @Html.DisplayFor(modelItem => tc.taskName)
                        </div>
                    </div>
                
                    <!--Dropdown-->
                    <div class="pickups_body_half" style="display:none; margin-left:0%">
                        <div class="subitems_title">Apartment @Html.DisplayFor(modelItem => tc.RESERVATION.PROPERTY.propName)</div>
                        <div class="space_10"></div>
                        <div class="subitems_body_half">@Html.DisplayFor(modelItem => tc.taskDetails)</div>
                        <div class="space_10"></div>

                        <div class="edit-delete" style="float:right;">
                            @if ((int)Session["userPerm"] <= 2)
                            {
                                string edit_link = "/Home/EditTask?taskId=" + tc.taskID + "&redirectURL=" + Request.Url.AbsoluteUri;
                                <a href="@edit_link"><img src="../../images/edit_icon_small.png" alt="edit" /></a>
                            }
                        </div>
                    </div>
                }
            }
            else
            {
                <p>No upcoming tasks.</p>   
            }
        </div>
        <div class="viewclientrow" style="color:#333333;">
            <font color="#777777">Memo:</font><br />
            @Html.DisplayFor(model => model.client.clientNotes)
        </div>
    </div> 
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        This page shows the client's details. To view/edit information pertaining to the client, click on one of the links
        contained in the grey box.
        <br /><br />
        To view the client's payment history and add a payment, click "View Payments..."
        <br />Please note that the quoted price for an unconfirmed reservation is ignored.
        <br /><br />
        To confirm an <strong>(Unconfirmed)</strong> reservation, press the "Confirm" button and add a deposit.
        <br />Please note that an unconfirmed reservation cannot have tasks added to it.
        <br /><br />
        To add a client task to a confirmed reservation, press the "+ Task" button.
        <br /><br />
        To delete a reservation, press the "cancel" button.
        <br /><br />
        To edit a reservation's details, such as the quoted price and start/end date, press the "edit" button.
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->